package com.xnfh.equipment.viewmodel

import com.xnfh.common.bean.GuanGaiBean
import com.xnfh.common.bean.WarningBean
import com.xnfh.equipment.viewmodel.base.BaseTokenViewModel
import com.xnfh.framework.bean.RespStateData
import org.json.JSONObject

/**
 * @Description:
 * @Author: ziheng
 * @CreateDate: 2023/12/27 14:29
 * @UpdateUser: ziheng
 * @UpdateDate: 2023/12/27 14:29
 * @UpdateRemark: 更新说明
 */
class EquipmentLogViewModel : BaseTokenViewModel() {

    private val equipmentLogViewModelRes = EquipmentLogViewModelRes()
    val warningBean = RespStateData<WarningBean>()

    val guanGaiBean = RespStateData<GuanGaiBean>()

    /**
     * 获取系统日志
     */
    fun requestLogList(gateWayId: String?, page: Int) = launch {
        val jsonObject = JSONObject()
        jsonObject.put("pageIndex", page)//当前页码
        jsonObject.put("pageSize", 20)//页大小
        jsonObject.put("orderBy", 0)//排序字符串: 0 desc,1 asc
        val jsonObjectBean = JSONObject()
        jsonObjectBean.put("gatewayid", gateWayId)// 网关id
        jsonObjectBean.put("msgType", 1)//0 为不限制，1 系统日志，2 预警日志
        jsonObjectBean.put("msgPriority", 0)//消息大类，0 为不限制
        jsonObject.put("searchInfo", jsonObjectBean)
        equipmentLogViewModelRes.requestSysemLog(
            creatRequestBody(jsonObject.toString()),
            warningBean
        )
    }

    /**
     * 获取灌溉日志
     */
    fun requestGuanGaiList(gateWayId: String?, page: Int) = launch {
        val jsonObject = JSONObject()
        jsonObject.put("pageIndex", page)//当前页码
        jsonObject.put("pageSize", 20)//页大小
        val jsonObjectBean = JSONObject()
        jsonObjectBean.put("gatewayId", gateWayId)// 网关id
        jsonObjectBean.put("logType", 120)//日志类型，0 为不限制,100, 主阀流量 110, 灌区流量 120, 阀门流量
        jsonObject.put("searchInfo", jsonObjectBean)
        equipmentLogViewModelRes.requestGuaiGai(
            creatRequestBody(jsonObject.toString()),
            guanGaiBean
        )
    }


}